home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessPieces ƒ / CChessPiece.cp < prev    next >
Text File  |  1993-05-26  |  1KB  |  69 lines

  1. ////////////
  2. //
  3. //    CChessPiece.cp
  4. //
  5. //    Abstract Chess Piece methods.
  6. //
  7. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  8. //
  9. ////////////
  10.  
  11. #include <stdlib.h>
  12. #include "CChessPiece.h"
  13. #include "CChessBoard.h"
  14.  
  15. extern CIconHandle gWhitePawnCicnHandle;
  16.  
  17. void CChessPiece::IChessPiece(short aColor)
  18. {
  19.     itsColor = aColor;
  20. }
  21.  
  22.  
  23. void CChessPiece::Draw(short rank, short file)
  24. {
  25.     // Null method -- must be overridden
  26. }
  27.  
  28.  
  29. Boolean    CChessPiece::IsValidMove(CChessBoard *aBoard, short newRank, short newFile)
  30. {
  31.     // this is the default method -- it returns false just in case.
  32.     return false;
  33. }
  34.  
  35.  
  36. short    CChessPiece::BoardLocationValue(CChessBoard *aBoard, short rank, short file)
  37. {
  38.     short    theKingRank,theKingFile;
  39.     short    rankDist,fileDist;    
  40.  
  41.     if (itsColor == White)
  42.     {
  43.         theKingRank = aBoard->blackKingRank;
  44.         theKingFile = aBoard->blackKingFile;
  45.     }
  46.     else
  47.     {
  48.         theKingRank = aBoard->whiteKingRank;
  49.         theKingFile = aBoard->whiteKingFile;
  50.     }
  51.     
  52.     rankDist = abs(theKingRank-rank);
  53.     fileDist = abs(theKingFile-file);
  54.     
  55.     return ((9 - rankDist) + (9 - fileDist)) * 2;
  56. }
  57.  
  58.  
  59. CIconHandle    CChessPiece::GetCicnHandle(void)
  60. {
  61.     // this is the default method which returns the pawn color icon handle --
  62.     // this method must be overridden
  63.     return gWhitePawnCicnHandle;
  64. }
  65.  
  66. void    CChessPiece::RegisterMove(short rank, short file)
  67. {
  68.     // this is the default method in case a piece has nothing to register.
  69. }